package com.chuangjiangx.member.manager.client.web.coupon.controller;


import com.chuangjiangx.commons.response.CamelResponse;
import com.chuangjiangx.commons.response.Response;
import com.chuangjiangx.commons.response.ResponseUtils;
import com.chuangjiangx.member.coupon.ddd.application.MbrCouponApplication;
import com.chuangjiangx.member.coupon.ddd.dal.dto.MbrHasCouponList;
import com.chuangjiangx.member.coupon.ddd.query.MbrCouponQuery;
import com.chuangjiangx.member.manager.basic.web.interceptor.Login;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * 卡券接口
 */
@RestController
@Api(value = "卡券接口", tags = "卡券")
@RequestMapping(value = "/mbr/coupon", produces = "application/json")
public class MbrHasCouponClientController {

    private final MbrCouponQuery mbrCouponQuery;
    private final MbrCouponApplication mbrCouponApplication;


    @Autowired
    public MbrHasCouponClientController(
            MbrCouponApplication mbrCouponApplication,MbrCouponQuery mbrCouponQuery) {
        this.mbrCouponApplication = mbrCouponApplication;
        this.mbrCouponQuery = mbrCouponQuery;
    }

    @ApiIgnore
    @RequestMapping(value = "/unlock/{verifyCode}")
    @Login
    public Response unlock(@PathVariable String verifyCode) {
        mbrCouponApplication.unlockMbrHasCoupon(verifyCode);
        return ResponseUtils.successCamel();
    }

    /**
     * 加载会员可用的卡券
     */
    @RequestMapping(value = "/member-use-coupon",method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    @Login
    @ApiOperation(value = "加载会员可用卡券")
    public CamelResponse<List<MbrHasCouponList>> mbrHasCouponList(Long id) {
        Assert.notNull(id, "  会员id不能为空");
        List<MbrHasCouponList> mbrHasCouponList = mbrCouponQuery.findMbrHasCouponList(id, 0);
        return (CamelResponse<List<MbrHasCouponList>>) ResponseUtils.successCamel(mbrHasCouponList);
    }
}
